<?php

class MenuPage {

    //当前主菜单ID
    static protected $main_menu_id = 1;
    //当前子菜单ID
    static protected $child_menu_id = 0;
    //当前二级菜单ID
    static protected $second_menu_id = 0;
    //所有顶级菜单
    static protected $main_menu_list = array();
    //当前页面的所有子菜单
    static protected $child_menu_list = array();

    //当前页面的主菜单信息
    //头部菜单
    static protected function getMenuList($obj_conn) {

        $aa = isset($_GET['way']) ? trim($_GET['way']) : '';
        if ($aa == 'aa') {
            self::$main_menu_id = 1;
        } else {

            $class_name = isset($_GET['C']) ? trim($_GET['C']) : '';
            if (empty($class_name)) {
                return false;
            }
            $function_name = isset($_GET['A']) ? trim($_GET['A']) : '';
            $way_name = isset($_GET['way']) ? trim($_GET['way']) : '';

            $current_menu = $obj_conn->getOneRow('tb_admin_menu', 'Fid,FcateId,FcateIds', "WHERE Flevel=3 AND Fclass='$class_name' AND Ffunction='$function_name' AND Fway='$way_name'");
//        self::$current_menu_info = $current_menu;     

            if (isset($current_menu['Fid'])) {
                $current_menu_arr = explode(',', $current_menu['FcateIds']);

                if (count($current_menu_arr) > 1) {
                    $main_menu_id = $current_menu_arr[1];
                } else {
                    $main_menu_id = $current_menu_arr[0];
                }
                self::$main_menu_id = $main_menu_id;
                self::$child_menu_id = $current_menu['Fid'];
                self::$second_menu_id = $current_menu['FcateId'];
            } else {
                $current_me = $obj_conn->getOneRow('tb_admin_menu', 'Fid', "WHERE Flevel=1 AND Fclass='$class_name' AND Ffunction='$function_name'");
                self::$main_menu_id = $current_me['Fid'];
            }
        }

        $user_ids = isset($_COOKIE['user']['id']) ? ($_COOKIE['user']['id']) : 1;
        $user_menu_ids = $obj_conn->getList('tb_admin_menu_level', 'Fid,FmenuIds', "WHERE Fid=$user_ids");
        foreach ($user_menu_ids as $FmenuIdss) {
            $user_menu_ids = "'" . str_replace(',', "','", $FmenuIdss['FmenuIds']) . "'";
        }

        self::$main_menu_list = $obj_conn->getList('tb_admin_menu', 'Fid,Fname,FcateId,Fclass,Ffunction,Fway', "WHERE FcateId=0 AND Fid IN ($user_menu_ids)", 'ORDER BY Fsort');
        $menu_list = $obj_conn->getList('tb_admin_menu', 'Fid,Fname,FcateId,Fclass,Ffunction,Fway', "WHERE Flevel>1 AND Fid IN ($user_menu_ids) AND Fstatus=1", 'ORDER BY FcateId,Fsort');
        //重新构造数组
        foreach ($menu_list as $ls) {
            self::$child_menu_list[$ls['FcateId']][$ls['Fid']] = $ls;
        }
        //找三个顶级
//        $current_me = $obj_conn->getOneRow('tb_admin_menu', 'Fid', "WHERE Flevel=1 AND Fclass='$class_name' AND Ffunction='$function_name'");
//        self::$ding_menu_id = $current_me['Fid'];
//        self::$head_menu = $obj_conn->getList('tb_admin_menu', 'Fid,Fname,Fclass,Ffunction', "WHERE Flevel = 1");
//
//        $class = isset($_GET['C']) ? trim($_GET['C']) : '';
//        $function = isset($_GET['A']) ? trim($_GET['A']) : '';
//        $current_menu = $obj_conn->getOneRow('tb_admin_menu', 'Fid', "WHERE Flevel=1 AND Fclass='$class' AND Ffunction='$function'");
//        print_r($current_menu);
//        //current_menu=Array ( [Fid] => 1 )
//        if (isset($current_menu['Fid'])) {
//            self::$head_menu_switch = $current_menu['Fid'];
//        } else {
//            return false;
//        }
    }

    static protected function getMsg($message, $href, $time = 5, $target = '_self') {
        $_SESSION['msg']['message'] = $message;
        $_SESSION['msg']['href'] = $href;
        $_SESSION['msg']['time'] = $time;
        $_SESSION['msg']['target'] = $target;
        /**
          setcookie('msg[status]', $status, time() + $time, ADMIN_FOLDER, DOMAIN_NAME);
          setcookie('msg[message]', $message, time() + $time, ADMIN_FOLDER, DOMAIN_NAME);
          setcookie('msg[href]', $href, time() + $time, ADMIN_FOLDER, DOMAIN_NAME);
          setcookie('msg[time]', $time, time() + $time, ADMIN_FOLDER, DOMAIN_NAME);
          setcookie('msg[target]', $target, time() + $time, ADMIN_FOLDER, DOMAIN_NAME);
         * 
         */
        header('location: ' . DOMAIN_NAME_WWW . '/index.php?C=Xitong&A=menuYes&way=aa');
        exit;
    }

}
